﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;

using Main.src.display;
using Main.src.input;
using Main.src.util;
using Main.src.game;

namespace Main.src.game
{
    public class Campo
    {
        Vector2 ballInputPosition;        
        Rectangle goalPositionLeft;
        Rectangle goalPositionRight;
        Rectangle fieldBounds;
        Sprite imagem;
        int keeperDistanceFromGoal = 20;

        public Rectangle limiteCampo
        {
            get
            {
                return fieldBounds;
            }
        }

        public Campo()
        {

            setBoundsAndImage();

            ballInputPosition.X = (int)(fieldBounds.Width / 2);
            ballInputPosition.Y = fieldBounds.Height;

            setGoals();

            

            setAxis(8);
        }

        private void setAxis(int  numberOfAxis)
        {
            List<Vareta> varetas = new List<Vareta>();
            Vareta varetaTemp;            

            for (int i = 0; i < numberOfAxis; i++)
            {
                varetaTemp = new Vareta(new Sprite(Cache.GetTexture("TVareta")));
                varetaTemp.Posicao = new Vector2(((fieldBounds.Width - ( 2*keeperDistanceFromGoal + varetaTemp.imagem.Width)) / (numberOfAxis - 1)) * i + keeperDistanceFromGoal, 0);
                varetaTemp.imagem.LayerDepth = 1;
                varetas.Add(varetaTemp);
            }
       
        }

        private void setGoals()
        {
            goalPositionLeft.X = fieldBounds.X;
            goalPositionLeft.Y = fieldBounds.Y + fieldBounds.Height / 3;
            goalPositionLeft.Width = 0;
            goalPositionLeft.Height = fieldBounds.Height / 3;

            goalPositionRight.X = fieldBounds.X + fieldBounds.Width;
            goalPositionRight.Y = fieldBounds.Y + fieldBounds.Height / 3;
            goalPositionRight.Width = 0;
            goalPositionRight.Height = fieldBounds.Height / 3;
            
            Console.WriteLine(fieldBounds.X);
            Console.WriteLine(fieldBounds.Y);
        }

        private void setBoundsAndImage()
        {
            fieldBounds.X = 0;
            fieldBounds.Y = 30;

            imagem = new Sprite(Cache.GetTexture("TCampoFutebol"));
            imagem.Position.X = fieldBounds.X;
            imagem.Position.Y = fieldBounds.Y;

            fieldBounds.Width = imagem.Width;
            fieldBounds.Height = imagem.Height;
        }
    }
}
